<template>
  <div>
    <Navbar />
    <h1>图表示例</h1>
    <v-chart :option="chartOptions" autoresize class="chart" />
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import Navbar from '@/components/Navbar.vue'
import VChart from 'vue-echarts'
import * as echarts from 'echarts'

// 引入 ECharts 模块，确保模块已经注册
import { use } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers'
import { BarChart } from 'echarts/charts'
import {
  TitleComponent,
  TooltipComponent,
  GridComponent,
  LegendComponent
} from 'echarts/components'

// 注册必要的 ECharts 模块
use([CanvasRenderer, BarChart, TitleComponent, TooltipComponent, GridComponent, LegendComponent])

const chartOptions = ref(null)

onMounted(() => {
  chartOptions.value = {
    title: {
      text: '示例图表'
    },
    tooltip: {},
    legend: {
      data: ['销量']
    },
    xAxis: {
      data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
    },
    yAxis: {},
    series: [
      {
        name: '销量',
        type: 'bar',
        data: [5, 20, 36, 10, 10, 20]
      }
    ]
  }
})
</script>

<style scoped>
.chart {
  width: 100%;
  height: 500px;
}
</style>
